<template>
	<view class="user clearfix  bg-shop hv100">
		<cu-custom bgColor="bg-white " isBack>
			<block slot="content">设置</block>
		</cu-custom>
		<view class="flex align-center justify-between px15 f16 bg-white mt5 py20" @click="uploadPassport">
			<view class="flex align-center">头像</view>
			<view class="flex align-center justify-end" >
				<image :src="userInfo.headImg||uploadpic" class="block45 mr10 round" mode=""></image>
				<text class="cuIcon-right"></text>
			</view>
		</view>
		<view class="flex align-center justify-between px15 f16 bg-white mt1 py20" >
			<view class="flex align-center">ID</view>
			<text class="">{{userInfo.uid}}</text>
		</view>
		<!-- <view class="flex align-center justify-between px15 f16 bg-white mt1 py20">
			<view class="flex align-center">介绍人</view>
			<text class="">张敏</text>
		</view> -->
		<view class="flex align-center justify-between px15 f16 bg-white mt5 py20">
			<view class="flex align-center">邀请码</view>
			<text class="">{{userInfo.tjmNum}}</text>
		</view>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import uploadFile from '@/mixins/uploadFile'
export default {
	mixins: [uploadFile],
	data() {
		return {
			uploadpic:''
		}
	},
	computed: {
		...mapState(['userInfo','baseURL'])
	},
	
	methods: {
		...mapActions(['logout','getUser']),
		async uploadPassport() {
			let [err, res] = await uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album']
			})
			if (res) {
				this.uploadpic = res.tempFilePaths.shift()
				this.up()
			}
		},
		async up(){
			let formData = {  }
			if (this.uploadpic) {
				let {
					data: { updateToken, updateUrl, prefixUrl }
				} = await this.$http.post('user.getQnToken', {}, { tipConfig: { storeLoading: true } })
				let img = await this.qnUploadFile({ url: updateUrl, prefixUrl, files: this.uploadpic, formData: { token: updateToken } })
				formData.headImg = img[0]
			}
			await this.$http.post('user.saveinfo', formData, { tipConfig: { storeLoading: true, isSuccessTip: true} })
			this.getUser()
		}
	}
}
</script>

<style lang="less">
.mt1s{
	margin-top: 1rpx;
}
.set-button{
	width: calc(100% - 60rpx);
	margin-left: 30rpx;
	height: 102rpx;
	background-color:#FE4725;
	color: #FFFFFF;
	border-radius: 40rpx;
	position: fixed;
	bottom: 40rpx;
}
</style>
